//
//  KTNewCollectionCell.m
//  KTLotteryTicket
//
//  Created by CoolKi on 16/3/7.
//  Copyright © 2016年 CoolKi. All rights reserved.
//

#import "KTNewCollectionCell.h"
#import "KTRootTabBarC.h"

@interface KTNewCollectionCell ()
@property (nonatomic,weak)UIImageView * imgView;

@end

@implementation KTNewCollectionCell

//懒加载 (get方法)
//1.判断是否存在，不存在，创建，存在直接返回
//2.不能使用 self.本身属性 关键字，防止循环引用
- (UIImageView *)imgView{
    if (_imgView == nil) {
        UIImageView * imgView = [[UIImageView alloc]init];
        imgView.frame = self.bounds;
        [self.contentView addSubview:imgView];
        _imgView = imgView;
    }
    return _imgView;
}

- (void)setImg:(UIImage *)img{
    _img = img;
    self.imgView.image = img;
}

//懒加载立即体验按钮
- (UIButton *)startBtn {
    
    if (_startBtn == nil) {
        UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [startBtn setImage:[UIImage imageNamed:@"guideStart"] forState:UIControlStateNormal];
        //自适应大小
        [startBtn sizeToFit];
        //设置按钮位置
        startBtn.center = CGPointMake(self.width * 0.5, self.height * 0.8);
        _startBtn = startBtn;
        [self.contentView addSubview:startBtn];
        //监听按钮的点击
        [startBtn addTarget:self action:@selector(startBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _startBtn;
}

//点击开始按钮时调用
- (void)startBtnClick {
    //跳到应用程序的主框架
    KTRootTabBarC *tabBarVC = [[KTRootTabBarC alloc] init];
    [UIApplication sharedApplication].keyWindow.rootViewController = tabBarVC;
}

////设置立即体验按钮是否隐藏显示
- (void)setJoinBtnWithCurrentIndexPath:(NSIndexPath *)indexPath countItems:(NSInteger)count{
    //如果是最后一个item
    if (indexPath.item == count - 1) {
        //立即体验按钮显示
        self.startBtn.hidden = NO;
    }else {
        //立即体验按钮隐藏
        self.startBtn.hidden = YES;
    }
}


@end
